@Service
public class RatingService {
    @Autowired
    private RatingRepository ratingRepository;

    public Rating rateSong(Long userId, Long songId, int rating) {
        // 检查用户是否已经评分过该歌曲，如果已评分则更新评分，否则创建新的评分记录
        Rating existingRating = ratingRepository.findByUserIdAndSongId(userId, songId);
        if (existingRating != null) {
            existingRating.setRating(rating);
            return ratingRepository.save(existingRating);
        } else {
            Rating newRating = new Rating();
            newRating.setUserId(userId);
            newRating.setSongId(songId);
            newRating.setRating(rating);
            return ratingRepository.save(newRating);
        }
    }

    // 其他评分相关方法...
}
